package com.ruoyi.web.controller.qif;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.qif.domain.QifGuest;
import com.ruoyi.qif.domain.RoomCategoryVO;
import com.ruoyi.qif.service.IQifGuestService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qif.domain.QifRoom;
import com.ruoyi.qif.service.IQifRoomService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 锜风公寓-房间Controller
 *
 * @author David
 * @date 2025-10-05
 */
@Controller
@RequestMapping("/qif/room")
public class QifRoomController extends BaseController {
    private String prefix = "qif/room";

    @Autowired
    private IQifRoomService qifRoomService;


    @RequiresPermissions("qif:room:view")
    @GetMapping()
    public String room() {
        return prefix + "/room";
    }
    /**
     * 跳转到分类房间列表页面（并携带数据）
     */
    @RequiresPermissions("qif:room:view")
    @GetMapping("/category")
    public String category(QifRoom qifRoom, ModelMap mmap) {
        // 查询分类数据
        RoomCategoryVO categoryVO = qifRoomService.selectRoomByCategory(qifRoom);
        mmap.put("categoryData", categoryVO);
        return prefix + "/roomCategory"; // 新增的页面模板
    }
    /**
     * 查询锜风公寓-房间列表
     */
    @RequiresPermissions("qif:room:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QifRoom qifRoom) {
        startPage();
        List<QifRoom> list = qifRoomService.selectQifRoomList(qifRoom);
        return getDataTable(list);
    }

    @Log(title = "房间导入", businessType = BusinessType.EXPORT)
    @RequiresPermissions("qif:room:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<QifRoom> util = new ExcelUtil<QifRoom>(QifRoom.class);
        List<QifRoom> userList = util.importExcel(file.getInputStream());
        String message = qifRoomService.importUser(userList, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }
    @RequiresPermissions("qif:room:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<QifRoom> util = new ExcelUtil<QifRoom>(QifRoom.class);
        return util.importTemplateExcel("房间数据");
    }
    /**
     * 导出锜风公寓-房间列表
     */
    @RequiresPermissions("qif:room:export")
    @Log(title = "房间导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QifRoom qifRoom) {
        List<QifRoom> list = qifRoomService.selectQifRoomList(qifRoom);
        ExcelUtil<QifRoom> util = new ExcelUtil<QifRoom>(QifRoom.class);
        return util.exportExcel(list, "锜风公寓-房间数据");
    }

    /**
     * 新增锜风公寓-房间
     */
    @RequiresPermissions("qif:room:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存锜风公寓-房间
     */
    @RequiresPermissions("qif:room:add")
    @Log(title = "锜风公寓-房间", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QifRoom qifRoom) {
        return toAjax(qifRoomService.insertQifRoom(qifRoom));
    }

    /**
     * 修改锜风公寓-房间
     */
    @RequiresPermissions("qif:room:edit")
    @GetMapping("/edit/{roomId}")
    public String edit(@PathVariable("roomId") Long roomId, ModelMap mmap) {
        QifRoom qifRoom = qifRoomService.selectQifRoomByRoomId(roomId);
        mmap.put("qifRoom", qifRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存锜风公寓-房间
     */
    @RequiresPermissions("qif:room:edit")
    @Log(title = "锜风公寓-房间", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QifRoom qifRoom) {
        return toAjax(qifRoomService.updateQifRoom(qifRoom));
    }

    /**
     * 删除锜风公寓-房间
     */
    @RequiresPermissions("qif:room:remove")
    @Log(title = "锜风公寓-房间", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(qifRoomService.deleteQifRoomByRoomIds(ids));
    }

    /**
     * 查询房客详细
     */
    @RequiresPermissions("qif:guest:list")
    @GetMapping("/detail/{roomId}")
    public String detail(@PathVariable("roomId") Long roomId, ModelMap mmap) {
        mmap.put("room", qifRoomService.selectQifRoomByRoomId(roomId));
        mmap.put("roomList", qifRoomService.selectQifRoomList(new QifRoom()));
        return "qif/guest/guest";
    }


}
